
(function () {
    var core = ecui,
        util = core.util,
        ui = ecui.ui,
        dom = ecui.dom;

    Object.assign(
        NS.data,
        {
        }
    );
    Object.assign(
        NS.ui,
        {
            EditCostDetailSubmitBtn: ecui.inherits(
                ui.Control,
                function (el, options) {
                    ui.Control.call(this, el, options);
                    this._bAgain = options.again;
                },
                {
                    onclick: function () {
                        var data = {};
                        var viald = ecui.esr.parseObject(document.forms.editCostDetailForm, data);
                        if (viald) {
                            if (ecui.esr.getData('fromEdit') === 'true') {
                                ecui.dispatchEvent(ecui.esr.findRoute(this).owner, 'change', { item: data });
                                history.go(-1);
                            }
                        } else {
                            ecui.tip('warn', '请完善必填信息');
                        }
                    }
                },
                ui.Submit
            )
        }
    );
    ecui.esr.addRoute('editCostDetail', {
        model: [''],
        weight: 4,
        frame: true,
        onbeforerequest: function (context) {
            context.num = mao.util.getTimeRandom();
        },
        onbeforerender: function (context) {
            if (mao.info.costDetailItem) {
                context.detail = mao.info.costDetailItem;
                context.detail.costTypeDesc = mao.info.baseInfoMap.finCostType[context.detail.costType] || '';
                delete mao.info.costDetailItem;
            }
            // 处理费用类型数据
            var finCostTypeTree = [];
            var tmp;
            mao.info.baseInfo.finCostType.forEach(function (item) {
                if (item.id) {
                    tmp.children.push(Object.assign({}, item));
                } else {
                    tmp = Object.assign({ children: [] }, item);
                    finCostTypeTree.push(tmp);
                }
            });
            NS.data.finCostTypeTree = finCostTypeTree;
        },
        onafterrender: function (context) {
        }
    });
}());

